package com.common.library.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
 * 解决垂直RecyclerView 嵌套水平 RecyclerView
 * 感觉没有效果......
 */
public class NestingRecyclerView extends RecyclerView {
//    private static final int INVALID_POINTER = -1;
//    private int mScrollPointerId = INVALID_POINTER;
//    private int mInitialTouchX, mInitialTouchY;
//    private int mTouchSlop;
    private double scale = 1.5f;//滚动速度

    public NestingRecyclerView(Context context) {
        super(context);
    }

    public NestingRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public NestingRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    public void setflingScale(double scale){
        this.scale = scale;
    }
    @Override
    public boolean fling(int velocityX, int velocityY) {
        velocityX *= scale;
        return super.fling(velocityX, velocityY);
    }
//    @Override
//    public void setScrollingTouchSlop(int slopConstant) {
//        super.setScrollingTouchSlop(slopConstant);
//        final ViewConfiguration vc = ViewConfiguration.get(getContext());
//        switch (slopConstant) {
//            case TOUCH_SLOP_DEFAULT:
//                mTouchSlop = vc.getScaledTouchSlop();
//                break;
//            case TOUCH_SLOP_PAGING:
//                mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(vc);
//                break;
//            default:
//                break;
//        }
//    }
//    @Override
//    public boolean onInterceptTouchEvent(MotionEvent e) {
//        final int action = MotionEventCompat.getActionMasked(e);
//        final int actionIndex = MotionEventCompat.getActionIndex(e);
//        switch (action) {
//            case MotionEvent.ACTION_DOWN:
//                mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
//                mInitialTouchX = (int) (e.getX() + 0.5f);
//                mInitialTouchY = (int) (e.getY() + 0.5f);
//                return super.onInterceptTouchEvent(e);
//            case MotionEventCompat.ACTION_POINTER_DOWN:
//                mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex);
//                mInitialTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
//                mInitialTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
//                return super.onInterceptTouchEvent(e);
//            case MotionEvent.ACTION_MOVE: {
//                final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId);
//                if (index < 0) {
//                    return false;
//                }
//                final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f);
//                final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
//                if (getScrollState() != SCROLL_STATE_DRAGGING) {
//                    final int dx = x - mInitialTouchX;
//                    final int dy = y - mInitialTouchY;
//                    final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally();
//                    final boolean canScrollVertically = getLayoutManager().canScrollVertically();
//                    boolean startScroll = false;
//                    if (canScrollHorizontally && Math.abs(dx) > mTouchSlop && (Math.abs(dx) >= Math.abs(dy) || canScrollVertically)) {
//                        startScroll = true;
//                    }
//                    if (canScrollVertically && Math.abs(dy) > mTouchSlop && (Math.abs(dy) >= Math.abs(dx) || canScrollHorizontally)) {
//                        startScroll = true;
//                    }
//                    return startScroll;
//                }
//                return super.onInterceptTouchEvent(e);
//            }
//            default:
//                return super.onInterceptTouchEvent(e);
//        }
//    }
}
